var hdreservsum = (function (){

    this.init = function (){
        this.updateReserveSum();
        $("#btnReserveSum").click( function(){
            var tempSum = "", str, i, temp;
            str = $("#txtReserveSum").val().split(',');
            for (i = 0; i < str.length; i += 1) {
                tempSum += str[i];
            }
            var newData = {
                ReserveID:parseInt($("#selReserveSumList option:selected").val()),
                AccountID:parseInt($("#selReserveSumAccountList option:selected").val()),
                Sum:parseFloat(tempSum)
            };
            data.reserveSum(newData);
            $("#txtReserveSum").val("");
            hdcurrentstate.show();
        });
    };
    this.updateReserveSum = function(){
        data.getAccountList( function (results) {
            var i, num, str = "";
            num = results.rows.length;
            if (num !== 0) {
                for(i=0; i < num; i += 1){
                    str += "<option value='" + results.rows.item(i).AccountID + "'>" + results.rows.item(i).Name + "</option>";
                }
                $("#selReserveSumAccountList").html(str).selectmenu("refresh",true);

            }
        });
        data.getReservedList( function( results ){
            var i, num, str = "";
            num = results.rows.length;
            if (num !== 0) {
                for(i=0; i < num; i += 1){
                    str += "<option value='" + results.rows.item(i).ReserveID + "'>" + results.rows.item(i).Name + "</option>";
                }
                $("#selReserveSumList").html(str).selectmenu('refresh',true);
            }
        });
    };
    this.init();
    return this;
}(hdreservsum || {}));
